package com.bing.beike.common.exception;



import com.bing.beike.common.result.CommonResult;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理业务异常（示例）
    @ExceptionHandler(value = RuntimeException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CommonResult<?> handleRuntimeException(HttpServletRequest req, RuntimeException e) {
        return CommonResult.error(500, e.getMessage());
    }

    // 处理404异常
    @ExceptionHandler(value = ResourceNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public CommonResult<?> handleNotFoundException(HttpServletRequest req, ResourceNotFoundException e) {
        return CommonResult.error(404, e.getMessage());
    }
}
